<template>
    <div class="setting">
        <p>通知开关</p>
        <div class="item">
            <div class="title">
                支付完成通知<van-switch v-model="pay" @change="notice('pay')" size="16px" />
            </div>
        </div>
        <div class="item">
            <div class="title">
                库存不足通知<van-switch v-model="stock" @change="notice('stock')" size="16px" />
            </div>
            <div class="des">当库存不足50时将给您发送通知</div>
        </div>
        <div class="item">
            <div class="title">
                发货通知<van-switch v-model="delive" @change="notice('delive')" size="16px" />
            </div>
        </div>
        <div class="item">
            <div class="title">
                收货通知<van-switch v-model="collect" @change="notice('collect')" size="16px" />
            </div>
        </div>
    </div>
</template>
<script>
export default {
    data(){
        return{
            id:null,
            pay:true,//支付
            delive:true,//发货
            collect:true,//收货
            stock: true,//库存
        }
    },
    created(){
        this.id = this.$route.params.id
    },
    mounted(){
        this.getList()
        console.log(this.$route.params.id)
    },
    methods:{
        //获取列表
        async getList(){
            let {data:{code,data}} = await this.$http.get(this.$api.sendList,{
                id:this.id
            })
            if (code === 0) {
                this.pay= data[0]==0?true:false//支付
                this.delive=data[2]==0?true:false//发货
                this.collect=data[3]==0?true:false//收货
                this.stock=data[1]==0?true:false//库存
            }
        },
        //修改状态
        async notice(e){
            let value = 0
            switch (e) {
                case 'pay':
                    value = this.pay?0:1
                    break;
                case 'delive':
                    value = this.delive?0:1
                    break;
                case 'collect':
                    value = this.collect?0:1
                    break;
                default:
                    value = this.stock?0:1
                    break;
            }
            let {data:{code,data},} = await this.$http.get(this.$api.sendSetup,{
                id:this.id,
                field:e,
                num:value
            })
            if(code === 0){
                this.$toast.success(data);
            }
        }
    }
}
</script>
<style lang="scss" scoped>
    .setting{
        
        min-height: 100vh;;
        background-color: #f1f1f1;
        p{
            padding: 1rem ;
            color:#999
        }
        .item{
            background-color: #fff;
            margin-bottom: 1px;
            padding: 1rem;
            .title{
                display: flex;
                font-size: 14px;
                justify-content: space-between;
                justify-items: center;
            }
            .des{
                font-size: 12px;
                margin-top: 0.5rem;
                color:#999
            }
        }
    }
</style>